import { MyShaderSprite } from "./shader/MyShaderSprite";

export class testShaderSprite extends MyShaderSprite {
    // mesh名称，自己随便定义一个
    protected meshName: string = "ballMesh";
    // 定点数据名称（shader中的变量名，数据类型，占的数据个数
    attributes = [
        ["posuv", Laya.glTFAccessorComponentType.FLOAT, 4],
        ["uvCenter", Laya.glTFAccessorComponentType.FLOAT, 2],
    ];


    // 定点数据，根据自己shader的情况增减修改
    getVertices(x: any, y: any): any[] {
        let uvCenter = [];
        let uv = this.renderTexture['_uv'];
        uvCenter[0] = (uv[0] + uv[2] + uv[4] + uv[6]) / 4;
        uvCenter[1] = (uv[1] + uv[3] + uv[5] + uv[7]) / 4;
        let vertices = [];


        let tex = this.renderTexture;
        var width = this.width || tex.sourceWidth;
        var height = this.height || tex.sourceHeight;
        var wRate = width / tex.sourceWidth;
        var hRate = height / tex.sourceHeight;
        width = tex.width * wRate;
        height = tex.height * hRate;
        x = x - width / 2;
        y = y - height / 2;

        vertices.push(x);
        vertices.push(y);
        vertices.push(uv[0]);
        vertices.push(uv[1]);
        this.pushExtVertices(vertices, uvCenter);

        vertices.push(x + width);
        vertices.push(y);
        vertices.push(uv[2]);
        vertices.push(uv[3]);
        this.pushExtVertices(vertices, uvCenter);

        vertices.push(x + width);
        vertices.push(y + height);
        vertices.push(uv[4]);
        vertices.push(uv[5]);
        this.pushExtVertices(vertices, uvCenter);

        vertices.push(x);
        vertices.push(y + height);
        vertices.push(uv[6]);
        vertices.push(uv[7]);
        this.pushExtVertices(vertices, uvCenter);

        return vertices;
    }

    pushExtVertices(vertices, uvCenter) {
        vertices.push(uvCenter[0]);
        vertices.push(uvCenter[1]);
    }
}